|
|
|
|
|
|
|
If you think back to the process of sending commands to a modem by hand, you may remember that the modem responds with status messages such as OK or informational messages such as the Caller ID data or a register setting. The MS Comm Control captures these messages and stores them in a buffer. You use the control's Input property to pull information from this buffer into your program, typically by assigning it to a variable. In Listing 23.1, you check the InputBufferLen property to determine whether the control has any data waiting in the buffer. If data is present, you check the data with the Instr function to see whether the modem has responded to the initialization string with OK. |
|
|
|
|
|
|
|
|
|
The InputLen property controls the number of characters removed from the buffer when you access the Input property. Setting it to zero, as done here, causes every character in the buffer to be returned.  |
|
|
|
|
|
|
|
|
|
|
If the modem responds with OK, then you have successfully established communications with it and are ready to begin the process of checking for Caller ID information. To do so, you set the Enabled property of the timer to True, which starts the process. The only remaining item in the Main function is to display the last caller (stored in the INI file) on the form. The procedure DisplayList simply reads the values from the [Call##] section of the INI file and populates the labels on the form. |
|
|
|
|
|
|
|
|
The most important routines in the sample Caller ID program are CheckForCall and WriteCIDData, shown in Listing 23.2. CheckForCall takes care of handling the input from the modem, and WriteCIDData actually parses the Caller ID information into the INI file. |
|
|
|
|
|
|
|
|
Listing 23.2 CALLID.ZIPProcedures That Parse the Information from the MS Comm Control |
|
|
|
|
|
|
|
|
Sub CheckForCall()
Dim nPrevCount As Integer
Dim l As Long
Dim sFile As String
With frmMain
If .MSComm1.InBufferCount >= 2 Then
'STOP TIMER AND GET INPUT FROM COM PORT
.tmrMain.Enabled = False
sTemp = .MSComm1.Input
'If input is a small string then ignore
'It is just the first 'RING' response.
If Len(sTemp) < 10 Then
.tmrMain.Enabled = True
Exit Sub
End If |
|
|
|
|
|